<template>
	<view class="publicWelfare">
		<view class="back">
			<image class="back-img" @click="back" src="../../static/index/fanhui.png" mode=""></image>
			<text class="back-name">公益环保</text>
		</view>
		<view class="content" style="padding: 0 30rpx;">
			<view class="search-box">
				<u-search placeholder="请输入想要搜索的内容" v-model="keyword" :show-action="false" height="72" bgColor="#ffffff">
				</u-search>
			</view>
			<!-- 热门推荐 -->
			<!-- <view class="recommend">
				<view class="recommend-box" v-for="(item,index) in recommendList" :key="index">
					{{item}}
				</view>
			</view> -->
			<!-- banner -->
			<view class="banner">
				<view class="uni-padding-wrap">
					<view class="page-section swiper">
						<view class="page-section-spacing">
							<swiper class="swiper" :indicator-dots="indicatorDots" :autoplay="autoplay"
								:interval="interval" :duration="duration">
								<swiper-item v-for="(item,index) in bannerList1" :key='index'>
									<view class="swiper-item uni-bg-red">
										<image class="img-banner" :src="item.image" mode=""></image>
									</view>
								</swiper-item>
							</swiper>
						</view>
					</view>
				</view>
			</view>
			<!-- 四个模块 -->
			<view class="modules">
				<view class="modules-box" v-for="(item,index) in fourModels" :key="index">
					<view class="modules-text-box" @click="jumpClick(item)">
						{{item.text}}
					</view>
					<text>{{item.text2}}</text>
				</view>
			</view>
			<!-- 三个专题 -->
			<!-- <view class="special">
				<view class="special-left">
					<view class="special-left-top">
						<image src="../../static/publicwelfare/zhishu.png" mode=""></image>
						<view class="special-left-top-left">
							<text>植树公益专题</text>
							<text>捐赠积分将会运用到植树中</text>
							<text>立即进入</text>
						</view>
					</view>
					<view class="special-left-bottom">
						<image src="../../static/publicwelfare/zhishu.png" mode=""></image>
						<view class="special-left-top-left">
							<text>植树公益专题</text>
							<text>捐赠积分将会运用到植树中</text>
							<text>立即进入</text>
						</view>
					</view>
				</view>
				<view class="special-right" style="background-image: url('../../static/publicwelfare/juxing.png');">
					<text>保护水资源活动</text>
					<text>保护水资源刻不容缓</text>
					<text>立即进入</text>
				</view>
			</view> -->
			<view class="donate" style="background-image: url('../../static/publicwelfare/juan.png');" v-for="(item,index) in list">
			<!-- <view class="donate" :style="{backgroundImage:'url('+item.images+')'}" v-for="(item,index) in list"> -->
				<!-- <image class="donate-img" src="../../static/publicwelfare/tujian.png" mode=""></image> -->
				<text
					style="margin-top:180rpx;margin-left: 40rpx; 32rpx;font-weight: 400;color: #FFFFFF;">{{item.name}}（{{item.min_integral}}积分起捐）</text>
				<view class="donate-box">
					<view class="one">{{item.echanism.name}} <text
							style="font-size: 12px;font-weight: 400;color: #999999;">（{{item.echanism.contact_address}}）</text></view>
					<view class="two">助力进度 <text>{{item.already_integral}}/{{item.max_integral}}积分</text></view>
					<view class="percentage" style="display: flex;">
						<u-line-progress height="14" style="width: 440rpx;" active-color='#FF7200' :percent="item.progress"
							:show-percent="false"></u-line-progress>
					</view>
					<text class="jifen-btn" style="position: absolute;bottom: 16rpx;right: 26rpx;">去捐积分</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import AiProgress from '../../components/ai-progress/ai-progress.vue'
	import {getwelfareList} from '@/service/publicWelfare.js';//公益环保列表接口
	import {
		getBanner
	} from '@/service/banner.js' //banner
	export default {
		comments: {
			AiProgress
		},
		data() {
			return {
				percentage: '30',
				bannerList1: [],
				recommendList: ['服饰', '牛奶', '咖啡豆'],
				indicatorDots: false,
				autoplay: true,
				interval: 2000,
				duration: 500,
				keyword: '',
				fourModels: [{
					text: '公',
					text2: '公益助学',
					url: '/myPackageA/index/environment/environment'
				}, {
					text: '益',
					text2: '好风尚'
				}, {
					text: '在',
					text2: '敬老扶残'
				}, {
					text: '线',
					text2: '真善举'
				}],
				list:[],//公益环保列表接口
				progress:'',
				new_arr:[]
			}
		},
		onLoad() {
			this.getBanner();
			this.getwelfareList()
		},
		methods: {
			//获取列表
			getwelfareList(){
				let params ={
					type:'',
					mechanism_id:'',
					limit:10,
					page:1
				}
				getwelfareList(params).then(res=>{
					this.list = res.data.data
					let arr = res.data.data
					
					arr.forEach((item,index)=>{
						let a =  (item.already_integral/item.max_integral)*100
						let progress = parseInt(a)
						this.new_arr = this.list.map((item2,index2)=>{
							if(index==index2){
								this.progress = progress
							}
							return Object.assign(item2,{progress:this.progress})
						})
					})
					this.list = this.new_arr
				})
			},
			//获取banner、
			getBanner() {
				let params = {
					type: 6
				}
				getBanner(params).then(res => {
					console.log(res, '广告部分');
					this.bannerList1 = res.data
				})
			},
			back() {
				uni.navigateBack()
			},
			jumpClick(item) {
				uni.navigateTo({
					url: item.url
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	/deep/.percentage {
		margin-left: 0 !important;
		font-size: 12rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #FFFFFF;
	}

	.donate {
		width: 100%;
		height: 372rpx;
		background-repeat: no-repeat;
		background-size: 100% 100%;
		position: relative;
		display: flex;
		flex-direction: column;
		margin-bottom: 30rpx;

		.donate-box {
			position: relative;
			align-self: center;
			display: flex;
			flex-direction: column;
			width: 608rpx;
			height: 136rpx;
			background: #FFFFFF;
			border-radius: 10rpx;
			padding: 20rpx;

			.jifen-btn {
				width: 100rpx;
				height: 40rpx;
				background: #FF3333;
				border-radius: 24rpx;
				line-height: 40rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 20rpx;
				margin-left: 26rpx;
			}

			.one {
				font-size: 24rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #333333;
			}

			.two {
				font-size: 24rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #333333;
				margin: 8rpx 0;
			}
		}

		.donate-img {
			position: absolute;
			top: -10px;
			left: -12px;
			width: 96rpx;
			height: 112rpx;
		}
	}

	.publicWelfare {
		height: auto;
		padding-bottom: 40rpx;
	}

	.special {
		display: flex;
		margin-bottom: 30rpx;

		.special-left {
			flex: 1;
			height: 400rpx;

			.special-left-top {
				margin-bottom: 30rpx;
				padding: 20rpx 10rpx;
				display: flex;
				width: 392rpx;
				height: 214rpx;
				background: #FFFFFF;
				border-radius: 10px;

				image {
					width: 152rpx;
					height: 176rpx;
				}

				.special-left-top-left {
					margin-left: 12rpx;
					display: flex;
					flex-direction: column;

					text:first-child {
						font-size: 28rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #333333;
					}

					text:nth-child(2) {
						margin: 20rpx 0;
						font-size: 20rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #999999;
					}

					text:last-child {
						width: 98rpx;
						height: 40rpx;
						background: #FF7200;
						border-radius: 20rpx;
						font-size: 20rpx;
						text-align: center;
						font-family: Source Han Sans CN;
						font-weight: 400;
						line-height: 40rpx;
						color: #FFFFFF;
					}
				}
			}

			.special-left-bottom {
				margin-bottom: 30rpx;
				padding: 20rpx 10rpx;
				display: flex;
				width: 392rpx;
				height: 214rpx;
				background: #FFFFFF;
				border-radius: 10px;

				image {
					width: 152rpx;
					height: 176rpx;
				}

				.special-left-top-left {
					margin-left: 12rpx;
					display: flex;
					flex-direction: column;

					text:first-child {
						font-size: 28rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #333333;
					}

					text:nth-child(2) {
						margin: 20rpx 0;
						font-size: 20rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #999999;
					}

					text:last-child {
						width: 98rpx;
						height: 40rpx;
						background: #FF7200;
						border-radius: 20rpx;
						font-size: 20rpx;
						text-align: center;
						font-family: Source Han Sans CN;
						font-weight: 400;
						line-height: 40rpx;
						color: #FFFFFF;
					}
				}
			}
		}

		.special-right {
			width: 250rpx;
			height: 460rpx;
			background-color: #FFFFFF;
			border-radius: 10px;
			background-repeat: no-repeat;
			background-size: 100% 100%;
			display: flex;
			flex-direction: column;

			text:first-child {
				margin-top: 320rpx;
				margin-left: 12rpx;
				font-size: 28rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #333333;
			}

			text:nth-child(2) {
				margin-left: 12rpx;
				font-size: 20rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #999999;
				margin-top: 14rpx;
				margin-bottom: 14rpx;
			}

			text:last-child {
				margin-left: 12rpx;
				width: 98rpx;
				height: 40rpx;
				background: #FF7200;
				border-radius: 20rpx;
				font-size: 20rpx;
				text-align: center;
				font-family: Source Han Sans CN;
				font-weight: 400;
				line-height: 40rpx;
				color: #FFFFFF;
			}
		}
	}

	.modules {
		display: flex;
		justify-content: space-between;
		margin-bottom: 52rpx;

		.modules-box {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: center;

			.modules-text-box {
				width: 51px;
				height: 51px;
				background: #128055;
				border-radius: 50%;
				text-align: center;
				line-height: 51px;
				font-size: 60rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #FFFFFF;
				margin-bottom: 20rpx;
			}

			text {
				font-size: 32rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #666666;
			}
		}
	}

	.uni-padding-wrap {
		padding: 0;
	}

	.banner {
		margin-bottom: 40rpx;

		.swiper-item {
			height: 294rpx;

			.img-banner {
				width: 100%;
				height: 100%;
			}
		}
	}

	.recommend {
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;
		margin-bottom: 28rpx;

		.recommend-box {
			font-size: 24rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #999999;
			margin-right: 20rpx;
		}
	}

	/deep/.u-search {
		margin: 30rpx 0 !important;
		box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.26);
		border-radius: 20rpx;
	}

	.back {
		padding-top: 80rpx;
		width: 100%;
		height: 176rpx;
		background-color: #24AE3E;
		display: flex;
		align-self: center;
		padding-left: 0 !important;
		padding-right: 0 !important;

		.back-img {
			width: 40rpx;
			height: 40rpx;
			margin-top: 10rpx;
		}

		.back-name {
			font-size: 18px;
			line-height: 31px;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #FFFFFF;
			margin-right: 18rpx;
		}
	}
</style>
